package com.SouthernWall_404.AgeSuitcase.Client.Gui.Screens;

import com.SouthernWall_404.AgeSuitcase.Common.API.GeneralAPI;
import com.SouthernWall_404.AgeSuitcase.Common.API.Info.FileInfo;
import com.SouthernWall_404.AgeSuitcase.Common.AgeSuitcase;
import com.SouthernWall_404.AgeSuitcase.Common.world.item.FileItem;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;

public class ConstractScreen extends Screen {

    private ResourceLocation constractScreenLocation=new ResourceLocation(AgeSuitcase.MODID,"textures/gui/screen/constract_bg.png");


    private int backGroundHeight=220;
    private int backGroundWidth =backGroundHeight*3/4;

    private String GUI=GeneralAPI.GUI+"constractscreen.";


    public ConstractScreen(Component p_96550_) {
        super(p_96550_);
    }

    @Override
    public void render(GuiGraphics guiGraphics, int p_281550_, int p_282878_, float p_282465_) {
        super.render(guiGraphics, p_281550_, p_282878_, p_282465_);

        this.renderBackground(guiGraphics);
    }

    @Override
    public void renderBackground(GuiGraphics guiGraphics) {

        int start_x=(this.width-this.backGroundWidth)/2;
        int start_y=(this.height-this.backGroundHeight)/3;

//        this.renderBackground(guiGraphics);


        guiGraphics.blit(constractScreenLocation,start_x,start_y,this.backGroundWidth,this.backGroundHeight,0f,0f,1152,1536,1152,1536);
//        super.renderBackground(guiGraphics);

        this.renderDate(guiGraphics,start_x,start_y);
        this.renderCode(guiGraphics,start_x,start_y);





    }

    private void renderDate(GuiGraphics guiGraphics,int start_x,int start_y)
    {
        FileInfo fileInfo=getFileInfo();
        PoseStack poseStack = guiGraphics.pose();
        poseStack.pushPose(); // 保存当前矩阵状态
        poseStack.scale(0.5f, 0.5f, 1.0f); // 缩放
        guiGraphics.drawString(Minecraft.getInstance().font, fileInfo.date,(start_x+6)*2,(start_y+2)*2,0x5D3207,false);
        poseStack.popPose(); // 恢复矩阵状态
    }
    private void renderCode(GuiGraphics guiGraphics,int start_x,int start_y)
    {
        FileInfo fileInfo=getFileInfo();
        PoseStack poseStack = guiGraphics.pose();
        poseStack.pushPose(); // 保存当前矩阵状态
        poseStack.scale(0.5f, 0.5f, 1.0f); // 缩放
        guiGraphics.drawString(Minecraft.getInstance().font, Component.translatable(GUI+"code",fileInfo.code),(start_x+this.backGroundWidth-55)*2,(start_y+2)*2,0x5D3207,false);
        poseStack.popPose(); // 恢复矩阵状态
    }

    private FileInfo getFileInfo()
    {
        Player player=Minecraft.getInstance().player;
        ItemStack itemStack=player.getItemInHand(InteractionHand.MAIN_HAND);
        FileInfo fileInfo= FileItem.getFile(itemStack);
        return fileInfo;
    }
}
